//
//  WBSearchView.swift
//  weibobo
//
//  Created by KIMI on 16/9/20.
//  Copyright © 2016年 KIMI. All rights reserved.
//

import UIKit

class WBSearchView: UIView {

    @IBOutlet weak var searchTextField: UITextField!
    
    @IBOutlet weak var searchButton: UIButton!

    @IBOutlet weak var searchTextFeildRightConstraint: NSLayoutConstraint!
    @IBAction func textFielddidBeganAction(_ sender: AnyObject) {
        
        searchTextFeildRightConstraint.constant = searchButton.width
        
        UIView.animate(withDuration: 0.3) { 
            
            self.layoutIfNeeded()
        }
        
    }
    //搜索按钮的点击事件
    @IBAction func searchBtnAction(_ sender: AnyObject) {
        
        //辞去第一响应者
        searchTextField.resignFirstResponder()
        //重新设置约束
        searchTextFeildRightConstraint.constant = 0
        
        UIView.animate(withDuration: 0.3) { 
            
            self.layoutIfNeeded()
        }
    }
    
    //提供一个通过xib创建对象的类方法
    class func searchView() -> WBSearchView{
        
        return UINib(nibName: "WBSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last as! WBSearchView
        
        
    }
    
//        override func awakeFromNib() {
//            searchTextField.layer.borderColor = UIColor.magenta.cgColor
//            searchTextField.layer.borderWidth = 2
//            searchTextField.layer.cornerRadius = 5
//            searchTextField.layer.masksToBounds = true
//        }
    
}
